// pages/threeDetail/threeDetail.js
import {first} from "../../network/request" 
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      requestData: {
        url: '/goods/detail',
        data: {
          goods_id: options.goods_id
        }
      }
    })
    this.getList()
  },

  ji(e){
    wx.previewImage({
      
      current: this.data.getData.pics[e.currentTarget.dataset.num].pics_big,
      urls: this.data.getData.pics.map(v=>v.pics_big)
    })
  },
  
  tiaoTab(){
    wx.switchTab({
      url: '../../pages/shopCar/shopCar',
    })
  },

  getDataTmp: {},
  addShop(){
    let car = wx.getStorageSync("car") || []
    let index = -1
    if(car.length)
    index = car.findIndex(v=>v.goods_id===this.getDataTmp.goods_id)
    if(index===-1){
      this.getDataTmp.num = 1
      this.getDataTmp.chooseIt = true
      car.push(this.getDataTmp)
    }else{
      
      car[index].num++
      this.getDataTmp.chooseIt = true
      console.log(car[index].num+"个啦!")
    }
    wx.setStorageSync('car', car)

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  async getList(){
    const getData = await first(this.data.requestData)
    this.setData({
      getData
    })
    this.getDataTmp = this.data.getData
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})